package com.community.backend.service.impl;

import com.community.backend.mapper.SecurityMapper;
import com.community.backend.pojo.Security;
import com.community.backend.pojo.dto.LoginDTO;
import com.community.backend.pojo.dto.RegisterDTO;
import com.community.backend.pojo.dto.SecurityQueryDTO;
import com.community.backend.service.SecurityService;
import com.community.backend.utils.PageResult;
import com.community.backend.utils.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class SecurityServiceImpl implements SecurityService {
    @Autowired
    private SecurityMapper securityMapper;
    @Override
    public PageResult securityByPage(SecurityQueryDTO securityQueryDTO) {
        PageHelper.startPage(securityQueryDTO.getCurrentPage(),securityQueryDTO.getPageSize());
        Page<Security> page = securityMapper.pageQuery(securityQueryDTO);
        System.out.println("securityByPage分页信息"+page);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void update(Security security) {
        Integer rows = securityMapper.update(security);
    }

    @Override
    public void deleteById(String id) {
        Security security = new Security();
        security.setId(id);
        Integer rows = securityMapper.updateById(security);

    }

    @Override
    public void addUser(Security security) {
        security.setId(UUID.randomUUID().toString());
        security.setUsername(security.getName());
        security.setPassword("123456");
        security.setStatus("在职");
        security.setIsDelete("未删除");
        Integer rows = securityMapper.add(security);

    }

    @Override
    public Security login(LoginDTO loginDTO) {
        Security security = securityMapper.login(loginDTO.getUsername(), loginDTO.getPassword());
        return security;
    }
//没用
    @Override
    public void register(RegisterDTO registerDTO) {
        securityMapper.register(registerDTO);
    }

}
